<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="author" content="wangyuguo">
	<title>保证金管理</title>
	<script type="text/javascript" language="JavaScript" src="/script/common.js"></script>
<script type="text/javascript" language="JavaScript">
	var accountId;
	var cOrg = Common.cOrg();
	function load(){
		Eui.showNavigation();
		setPages(["listview","detview","lowlimitview"]);
		$("searchForm").currentOrg.value = cOrg.id
		DWR.call("creditTxService.getCreditUser",cOrg.id,function(res){
			if (res)
				DWR.call("creditTxService.findCreditUser",cOrg.uniqueId,function(v){
					var def = v.cardUser;
					creditUserId = def.uniqueId;
					def.orgName = v.creditOrg.name;
					def.orgUniqueId =v.creditOrg.uniqueId;
					def.orgLevel = Common.getText("org_level",v.creditOrg.orgLevel);
					if (v.accounts){
						var acc = v.accounts["user_"+AccountType.CREDIT]
						def.balance = Format.fenToYuan(acc.balance);
						def.lowLimit = Format.fenToYuan(Math.abs(acc.lowLimit));
					}
					Common.showDetail("creditUserDiv",def);
				});
		});
		createTable()
	}
	
	function createTable(){
		var columns = [];	
		columns[6] = {title:"操作",width:"18%",render:operator,align:"center",order:false} 		
		
		qt = new QueryTable("credit_manage_query","searchForm","datalist",columns,{
			buttons:[
				{value:"新增",actions:onNew}
			]
		});
		
		qt.showTable();				 
	}
	function operator(v,r){
		return "<div style='color:gray'><a href=# onclick=\"updateCredit("+r[5]+");return false;\">修改</a></div>";
	}	
	function onNew(){
		$("creditForm").reset();
		switchPage("detview");
	}
	function onSave(){
		if(!checkForm("creditForm"))return;
		if(showQuestion("您确认要创建保证金吗?")){
			var orgId = $("creditForm").orgId.value;
			DWR.call('creditTxService.createCreditAccount', orgId,function(v){
				showInformation("创建成功!")
				switchPage("listview");
				qt.showTable();
			});
		}
	}
	function updateCredit(id){
		accountId = id
		$("lowlimitform").reset();
		switchPage("lowlimitview");
		
	}
				
	//选择机构方法
	function creditSelOrg(){
		SystemMgnt.selOrg(function(sorg) {
			$('creditForm').orgId.value = sorg.uniqueId;
			$('creditForm').orgName.value = sorg.name;
		},{funcType : Constants.SELORG_ALL});
	}
	
	function saveLowLimit(){
		var form = $("lowlimitform");
		var lowLimit = form.lowLimit.value;
		DWR.call("creditTxService.saveCreditAccountLowLimit",cOrg.id,accountId,-1*(Format.yuanToFen(lowLimit)),function(){
			showInformation("保证金帐户修改成功!")
			switchPage("listview");
			qt.showTable();
		});
	}
</script>
</head>

<body onload="load()" class="noScroll">
		<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="listview" >	
		<form id="searchForm" name="searchForm" action="">
			<input type="hidden" name="currentOrg">
		</form>
		<div class="form" id="creditUserDiv">
			<div class="formTitle">帐户明细</div>	
			<form id="operationForm" action="">
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="viewTable" class="col2 label6">
					<tr class="label6">
						<td><label>机构名称</label> <span id="orgName" ></span></td>
						<td><label>机构编号</label> <span id="orgUniqueId" ></span></td>
					</tr>
					<tr class="label6">
						<td><label>等&nbsp;&nbsp;&nbsp;&nbsp;级</label> <span id="orgLevel" ></span></td>
						<td><label>帐号编号</label><span id="uniqueId"></span></td>
					</tr>
					<tr class="label6">
						<td><label>余&nbsp;&nbsp;&nbsp;&nbsp;额/元</label> <span id="balance" ></span></td>
						<td><label>透支额度/元</label><span id="lowLimit"></span></td>
					</tr>
				</table>
			</form>
		</div>
		<!--查询结构列表-->
		<div id="datalist"></div>	
	</div>
	<div id="detview" style="display:none;">
		<div class="listBorder">
		<form id="creditForm" name="creditForm" class="listForm"  action="">
			<div class="formTitle">新建保障金帐户</div>
			<table id="tbl" cellSpacing=0 cellPadding=4 width="100%" border=0>
			  	<tr>
			  		<td><label>机构名称</label> <input type="text" name="orgName" readonly class="readonly"></td>
				  	<td><label>保证金机构</label> <input type="text" name="orgId"  onblur="checkV(this,'number',true)"  readonly class="readonly"><a class="orga" href="#" onclick="creditSelOrg();">&nbsp;&nbsp;</a><span class="des">*</span></td>
			  	</tr>
			</table>
		</form >
		</div>
		<p><button type="submit" id="saveBut" name="saveBut"  onclick="onSave()" >保 存</button> <button type="submit" id="saveBut" name="saveBut"  onclick="switchPage('listview');" >返 回</button></p> 
	</div>
	<div id="lowlimitview" style="display:none;">
		<div class="listBorder">
		<form id="lowlimitform" name="lowlimitform" class="listForm"  action="">
			<div class="formTitle">保证金帐户维护</div>
			<table id="tbl" cellSpacing=0 cellPadding=4 width="100%" border=0>
			  	<tr>
				  	<td><label>透支额度/元</label> <input type="text" name="lowLimit" onblur="checkV(this,'amount',true)" ><span class="des">*</span></td>
			  	</tr>
			</table>
		</form >
		</div>
		<p><button type="submit" id="saveBut" name="saveBut"  onclick="saveLowLimit()" >保 存</button> <button type="submit" id="saveBut" name="saveBut"  onclick="switchPage('listview');" >返 回</button></p> 
	</div>
	

</body>
</html>